package com.qianfeng.zhangwei.sybl.ui;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.qianfeng.zhangwei.sybl.R;

public class BaseActivity extends AppCompatActivity implements View.OnClickListener {
    public ActionBar actionBar;
    public ActionBarHolder aHolder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initActionbar();
    }

    /**
     * 初始化AppActionBar
     */
    private void initActionbar() {
        /**
         * 第一步实例化actionbar
         */
        actionBar = getSupportActionBar();
        /**
         * 设置actionbar的模式
         * NAVIGATION_MODE_STANDARD 标准模式
         * NAVIGATION_MODE_TABS  导航tab模式
         *
         */
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayUseLogoEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
        //设置使用自定的View
        actionBar.setDisplayShowCustomEnabled(true);
        aHolder = new ActionBarHolder();
        actionBar.setCustomView(aHolder.rootView);
    }

    @Override
    public void onClick(View v) {

    }

    /**
     *
     */
    public class ActionBarHolder {
        public ImageView leftBtn;
        public ImageView rightBtn;
        public TextView title;
        public View rootView;

        public ActionBarHolder() {
            rootView = getLayoutInflater().inflate(R.layout.titlebar_layout, null);
            leftBtn = (ImageView) rootView.findViewById(R.id.titlebar_left_btn);
            title = (TextView) rootView.findViewById(R.id.titlebar_title);
            rightBtn = (ImageView) rootView.findViewById(R.id.titlebar_right_btn);
        }

        /**
         *
         */
        public void showGiftlTitle() {
            aHolder.leftBtn.setBackgroundResource(R.mipmap.ic_default_avatar);
            aHolder.leftBtn.setVisibility(View.VISIBLE);
            aHolder.title.setBackgroundResource(R.drawable.titlebar_search_selector);
            aHolder.title.setTextColor(getResources().getColor(R.color.gray));
            aHolder.title.setText("搜礼包");
            aHolder.title.setTextSize(16);
            aHolder.title.setGravity(Gravity.LEFT);
            aHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.mipmap.ic_search), null);
            aHolder.title.setOnClickListener(BaseActivity.this);
            aHolder.rightBtn.setVisibility(View.GONE);
        }

        /**
         *
         */
        public void showActivityTitle() {
            aHolder.leftBtn.setVisibility(View.GONE);
            aHolder.title.setText("社区活动");
            aHolder.title.setTextColor(getResources().getColor(R.color.black));
            aHolder.title.setTextSize(18);
            aHolder.title.setBackgroundResource(R.color.transparent);
            aHolder.title.setGravity(Gravity.CENTER);
            aHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
            aHolder.title.setOnClickListener(BaseActivity.this);
            aHolder.rightBtn.setVisibility(View.GONE);
        }

        public void showGameAndMoneyTitle() {
            aHolder.leftBtn.setBackgroundResource(R.mipmap.ic_default_avatar);
            aHolder.leftBtn.setVisibility(View.VISIBLE);
            aHolder.title.setBackgroundResource(R.drawable.titlebar_search_selector);
            aHolder.title.setTextColor(getResources().getColor(R.color.gray));
            aHolder.title.setText("搜礼包");
            aHolder.title.setTextSize(16);
            aHolder.title.setGravity(Gravity.LEFT);
            aHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.mipmap.ic_search), null);
            aHolder.title.setOnClickListener(BaseActivity.this);
            aHolder.rightBtn.setVisibility(View.GONE);
        }

        public void showMeTitle() {
            aHolder.leftBtn.setVisibility(View.GONE);
            aHolder.title.setText("我的信息");
            aHolder.title.setTextSize(18);
            aHolder.title.setTextColor(getResources().getColor(R.color.black));
            aHolder.title.setBackgroundResource(R.color.transparent);
            aHolder.title.setGravity(Gravity.CENTER);
            aHolder.title.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
            aHolder.title.setOnClickListener(BaseActivity.this);
            aHolder.rightBtn.setVisibility(View.VISIBLE);
            aHolder.rightBtn.setImageResource(R.drawable.titlebar_msg_selector);
            aHolder.rightBtn.setOnClickListener(BaseActivity.this);
        }

    }


}
